package com.topcoder.srm517;

import java.util.HashSet;

public class MonochromaticBoard {
	public int theMin(String[] board) {
		int H = board.length;
		int W = board[0].length();
		
		HashSet<Integer> row = new HashSet<Integer>();
		HashSet<Integer> col = new HashSet<Integer>();
		
		for (int i=0; i<H; i++) {
			for (int j=0; j<W; j++) {
				if (board[i].charAt(j) == 'W') {
					row.add(i);
					col.add(j);
				}
			}
		}
		
		if (row.size()==0 && col.size()==0) return Math.min(H, W);
		
		return H + W - row.size() - col.size();
	}
}
